package org.example.springioc;

import org.example.springioc.Interface.Func;
import org.example.springioc.controller.HelloController;
import org.example.springioc.controller.UserController;
import org.example.springioc.model.UserObject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

//@ComponentScan(basePackages = {"org.example.springioc"})
@SpringBootApplication
public class SpringIocApplication {
    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);



        System.out.println("==========HelloController==========");
        HelloController helloController1 = context.getBean(HelloController.class);
        helloController1.demo();
        //Bean的名称,一定唯一  Bean的名称=类名的小驼峰形式
        HelloController helloController2 = (HelloController)context.getBean("helloController");
        helloController2.demo();
        //Bean的类型+名称
        HelloController helloController3 = context.getBean("helloController", HelloController.class);
        helloController3.demo();

        System.out.println("==================================================================================");

        /*System.out.println("==========类注解==========");
        HelloService helloService = context.getBean(HelloService.class);
        helloService.demo();
        HelloComponent helloComponent = context.getBean(HelloComponent.class);
        helloComponent.demo();
        HelloConfiguration helloConfiguration = context.getBean(HelloConfiguration.class);
        helloConfiguration.demo();
        HelloRepository helloRepository = context.getBean(HelloRepository.class);
        helloRepository.demo();*/

        System.out.println("===================================================================================");
        System.out.println("==========方法注解==========");
        //使用@Bean注解标识方法时,如果同一返回类型的方法只存在一个,可以使用.class
        //如果同一返回类型的方法存在多个,抛出NoUniqueBeanDefinitionException异常
        //@Primary
        /*UserObject userObject = context.getBean(UserObject.class);
        System.out.println("userObject:" + userObject);*/
        //方法名 = bean的名称,不存在小驼峰/命名规范,方法名 完全等于 bean的名称

        /*UserObject getUserObject1 = (UserObject)context.getBean("getUserObject1");
        System.out.println(getUserObject1);
        UserObject getUserObject2 = (UserObject)context.getBean("getUserObject2");
        System.out.println(getUserObject2);
        Object getUserObject3 = context.getBean("GETUserObject3");
        System.out.println(getUserObject3);*/

        System.out.println("===================================================================================");

        Func dataBaseFunc = (Func)context.getBean("dataBaseFunc");
        Func fileFunc = (Func)context.getBean("fileFunc");
        dataBaseFunc.init();
        fileFunc.init();

        System.out.println("===================================================================================");

        UserController userController = (UserController)context.getBean("userController");
        userController.demo();
    }
}
